package asteroids.statements;


import java.util.*;

import be.kuleuven.cs.som.annotate.Basic;

import asteroids.Ship;
import asteroids.expressions.*;
import asteroids.types.*;

public class TurnStatement extends ActionStatement {
	
	private Expression angle;

	public TurnStatement(int line, int column, Expression angle) {
		super(line, column);
		this.angle = angle;
	}

	@Basic
	public Expression getAngle() {
		return angle;
	}
	
	@Override
	public void execute(Ship ship) {
		ship.turn(((DoubleType) getAngle().evaluate(ship, ship.getProgram().getGlobals())).getValue());
	}

	@Override
	public List<String> getTypeCheckErrors(List<String> typeErrors, Map<String, Type> globalVariables) {
		if(getAngle().evaluate(null, globalVariables).getClass() != DoubleType.class) {
			typeErrors.add("Line: " + getLine() + " Column: " + getColumn() + " - Angle statement '" + getAngle().toString() + "' is expected to be from the type 'double'.");
		}
		typeErrors = getAngle().getTypeCheckErrorsExpressions(typeErrors, globalVariables);
		return typeErrors;
	}

}
